﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Otgruzka.ServicesClients;
using BusinessLogic.Security;
using System.Configuration;
using DataTier.Entities;

namespace Otgruzka.WebForms
{
    public partial class ProductListClear : System.Web.UI.Page
    {
        //protected void Page_PreInit(object sender, EventArgs e)
        //{
        //    string theme = ThemesEnum.BasicBlue;
        //    this.Theme = theme;
        //}

        protected void Page_Load(object sender, EventArgs e)
        {

        }


        /// <summary>
        /// Сохранение нового несуществующего продукта в БД
        /// </summary>
        /// <param name="ProductName"></param>
        /// <param name="Productquantity"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod()]
        public static int AddNonExistAndRebind(string ProductName, int Productquantity)
        {
            //(new Otgruzka.Controls.Product.ProductList()).AddNonExistAndRebind();
            ProductEntity product = new ProductEntity()
            {
                Product = new DataTier.Product()
                {
                    IsUnavailable = true,
                    ProductName = ProductName,
                },
                // TODO: Сделать заполнение значения Единицы измерения
                MeasureUnit = new ProductsClient().GetMeasureUnitById(UserPrincipal.Current.UserId, Convert.ToInt32(ConfigurationManager.AppSettings["DefaultMeasureUnitId"]))
            };

            try
            {
                int id = new ProductsClient().SaveProduct(UserPrincipal.Current.UserId, product);
                return id;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

    }
}